﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Crank.Core
{
    static class DefaultOptionalityPreparser
    {
        public static void Install()
        {
            Preprocessor.AddDirective("default", Process);
            DefaultOptionality.Value = true;
        }

        private static void Process(string[] args)
        {
            if (args == null || args.Length > 2)
                throw new Exception("Invalid use of the Default Optionality preprocessor instruction");
            if (args[0].ToUpper() == "NULL")
                DefaultOptionality.Value = false;
            else if (String.Format("{0} {1}", args[0], args[1]).ToUpper() == "NOT NULL")
                DefaultOptionality.Value = true;
            else
                throw new Exception("Invalid use of the Default Optionality preprocessor instruction");
        }

        #region Blackboard Properties

        private static IProperty<bool> DefaultOptionality = Blackboard.Create<bool>("DefaultOptionality");

        #endregion

    }
}
